package com.ita.iosa.servlet;

import java.io.IOException;

import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class VerifyServlet
 */
public class VerifyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String defaltUname = "admin";
	private static final String defaltPassword = "admin";

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public VerifyServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String name = request.getParameter("uname");
		String password = request.getParameter("password");
		if (name.equals(defaltUname)) {
			if (password.equals(defaltPassword)) {
				HttpSession session = request.getSession();
				session.setAttribute("userName", name);
				response.sendRedirect("AdminOperate");
			} else {
				HttpSession session = request.getSession();
				session.setAttribute("error", "Password error!");
				response.sendRedirect("Login");
			}
		} else {
			HttpSession session = request.getSession();
			session.setAttribute("error", "User name error!");
			response.sendRedirect("Login");
		}
	}

}
